package org.glickr

import groovy.transform.InheritConstructors
import groovy.util.slurpersupport.GPathResult

@InheritConstructors
class FlickrServiceException extends RuntimeException{
    String method   = ''
    String uri      = ''
    String api      = ''
    String status   = ''
    String code     = ''
    String message  = '' // todo figure out how to deal with inherited message in combination with the Map constructor

    FlickrServiceException(GPathResult response) {
        status  = response.@stat.toString()
        code    = response.err.@code.toInteger()
        message = response.err.@msg.toString()
    }
    FlickrServiceException() {
    }

    String toString() {
        return getMessage()
    }

    String getMessage() {
        if (api) {
            return "'${this.message}' calling FlickrService.${method}, remote server responsed '${status.toString().toUpperCase()}' with code '${code}' for method ${api}"
        } else if (method) {
            return "'${this.message}' calling FlickrService.${method}"
        } else {
            return "${this.message}"
        }
    }
}

@InheritConstructors
class FlickrServiceApiException    extends FlickrServiceException { }

@InheritConstructors
class FlickrServiceSyntaxException extends FlickrServiceException { }

@InheritConstructors
class FlickrServicePluginException extends FlickrServiceException { }
